<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>通知公告管理</title>
	<script type="text/javascript">
		$(document).ready(function() {
			layui.use(function(){
				let laydate = layui.laydate;
				laydate.render({
					elem: '#showDate',
				});
			});

			$("#inputForm").validate({
				submitHandler: function (form) {
					cancelSelect();
					form.submit();
				},
				errorClass: 'validation-invalid-label',
				highlight: function(element, errorClass) {
						$(element).removeClass(errorClass);
				},
				errorPlacement: function (error, element) {
					validateErrorPlacement(error, element);
				}
			});

			$('input[type=file]').on('change', function() {
				let file = $(this).prop('files')[0];
				console.log(file);
			});

			let _fileLen = $(".file-item").length;
			if(_fileLen < 1){
				$(':file').addClass('required');
			}
			$.validator.addMethod( "uniqueFile", function( value, element) {
				return  _fileLen < 1;
			}, $.validator.format( "请先删除已上传的附件" ) );
		});
	</script>
</head>
<body>
<div class="content">
	<div class="card">
		<div class="card-body">
			<form:form id="inputForm" method="post" target="mainFrame"
					   modelAttribute="sysNotice"  enctype="multipart/form-data"
					   action="${ctxAdmin}/sys/sysNotice/save" >
			<form:hidden path="id"/>
			<sys:message content="${message}"/>
			<div class="form-group row">
				<label class="col-sm-2 col-form-label">名称</label>
				<div class="col-sm-9">
					<form:input path="name" htmlEscape="false" maxlength="255" class="form-control "/>
				</div>
			</div>
			<div class="form-group row">
				<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>附件</label>
				<div class="col-sm-9">
					<div>
						<c:if test="${not empty sysNotice.sysFile}">
							<a href="#" class="dropdown-item file-item">
								<i class="mi-attach-file rotate-45"></i>
								<span>${sysNotice.sysFile.fileName}</span><span>（${sysNotice.sysFile.fileSize}）</span>
							</a>
						</c:if>
					</div>
					<input type="file" name="file" extension="docx,pdf,zip,rar" data-msg-extension="文件格式不正确">
				</div>
			</div>
			<div class="form-group row">
				<label class="col-sm-2 col-form-label">显示日期</label>
				<div class="col-sm-9">
					<input id="showDate" name="showDate" type="text" class="form-control" lay-key="1" value="<fmt:formatDate value='${sysNotice.showDate}' pattern='yyyy-MM-dd'/>"/>
				</div>
			</div>
			<%--<div class="form-group row">
				<label class="col-sm-3 col-form-label">内容</label>
				<div class="col-sm-8">
					<form:textarea path="content" htmlEscape="false" rows="4" class="form-control "/>
				</div>
			</div>
			<div class="form-group row">
				<label class="col-sm-3 col-form-label">类型</label>
				<div class="col-sm-8">
					<form:input path="type" htmlEscape="false" maxlength="1" class="form-control "/>
				</div>
			</div>--%>
			<div class="form-group row">
				<div class="col-sm-10 ml-auto">
					<shiro:hasPermission name="sys:sysNotice:edit">
						<button type="submit" class="btn btn-primary"><i class="icon-database-check mr-2"></i>保 存</button>
					</shiro:hasPermission>
					<button type="button" class="btn btn-light" onclick="cancelSelect()" ><i class="icon-database-arrow mr-2"></i>取 消</button>
				</div>
			</div>
		</form:form>
		</div>
	</div>
</div>
</body>
</html>